package com.isoftstone.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import com.isoftstone.entity.Register;
import com.isoftstone.entity.Role;
import com.isoftstone.entity.Users;
import com.isoftstone.entity.Patient;
import com.isoftstone.entity.Diagnosis;
import com.isoftstone.service.UncheckService;


@Controller
@RequestMapping("uncheck")
public class UncheckController {
	
	@Autowired
	private UncheckService uncheckService;
	
	@RequestMapping("Uncheck")
	public String getAllUncheck(ModelMap modelMap){
		// TODO Auto-generated method stub
		
		List<Register> register=uncheckService.getWaitingPatient();
		List<Patient> patient=uncheckService.getAllPatient();
		
		modelMap.addAttribute("register",register);
		modelMap.addAttribute("patient",patient);
		return "docStation/Uncheck";
			
		}
	
	@RequestMapping("deleteRegister")
	@ResponseBody
	public boolean deletRegister(String guahao_id){
		
		
		boolean flag = uncheckService.deleteRegister(guahao_id);
		return flag;		
	}
	
	@RequestMapping("getRegisterByGuahaoId")
	@ResponseBody
	public Register getRegisterByGuahaoId(String guahao_id){
		Register register = uncheckService.getRegisterByGuahaoId(guahao_id);
		return register;
	}
	
	@RequestMapping("editRegister")
	@ResponseBody
	public boolean editRegister(String guahao_id,int zhenduan_type){
		
		
		Register register=new Register();
		register.setGuahao_id(guahao_id);
		register.setZhenduan_type(zhenduan_type);
		
		boolean flag = uncheckService.editRegister(guahao_id,zhenduan_type);
		return flag;		
	}
	
	@RequestMapping("insertDiagnosis")
	@ResponseBody
	public boolean insertDiagnosis(String diagnose_id,String guahao_id,String patient_telling,String present_illness,String past_illness,String allergy_illness,Date date_illness,String diagnose_content,String diagnose_remark,String plan_illness){
		
		Diagnosis diagnosis=new Diagnosis();
		diagnosis.setDiagnose_id(diagnose_id);
		diagnosis.setGuahao_id(guahao_id);
		diagnosis.setPatient_telling(patient_telling);
		diagnosis.setPresent_illness(present_illness);
		diagnosis.setPast_illness(past_illness);
		diagnosis.setAllergy_illness(allergy_illness);
		diagnosis.setDate_illness(date_illness);
		diagnosis.setDiagnose_content(diagnose_content);
		diagnosis.setDiagnose_remark(diagnose_remark);
		diagnosis.setPlan_illness(plan_illness);
		
		boolean flag = uncheckService.insertDiagnosis(diagnose_id,guahao_id,patient_telling,present_illness,past_illness,allergy_illness,date_illness,diagnose_content,diagnose_remark,plan_illness);
		return flag;	
	}
	@InitBinder
	public void initBinder(WebDataBinder binder, WebRequest request) {
		
		//转换日期
		DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
	}
}
